
Object.defineProperty(exports, "__esModule", { value: true });
var http_1 = __webpack_require__(/*! _core/http */ "./src/core/http/index.ts");
var login_1 = __webpack_require__(/*! _core/login */ "./src/core/login/index.ts");
var analytics_1 = __webpack_require__(/*! _util/analytics */ "./src/core/utils/analytics.ts");
var base64_1 = __webpack_require__(/*! _util/base64 */ "./src/core/utils/base64.ts");
var constant = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var constant_1 = __webpack_require__(/*! _util/constant */ "./src/core/utils/constant.ts");
var deviceInfo_1 = __webpack_require__(/*! _util/deviceInfo */ "./src/core/utils/deviceInfo.ts");
var eventEmitter_1 = __webpack_require__(/*! _util/eventEmitter */ "./src/core/utils/eventEmitter.ts");
var getSvrTime_1 = __webpack_require__(/*! _util/getSvrTime */ "./src/core/utils/getSvrTime.ts");
var protocol_1 = __webpack_require__(/*! _util/protocol */ "./src/core/utils/protocol.ts");
var timer_1 = __webpack_require__(/*! _util/timer */ "./src/core/utils/timer.ts");
var typeChecker_1 = __webpack_require__(/*! _util/typeChecker */ "./src/core/utils/typeChecker.ts");
var userData_1 = __webpack_require__(/*! _util/userData */ "./src/core/utils/userData.ts");
var uuid_1 = __webpack_require__(/*! _util/uuid */ "./src/core/utils/uuid.ts");
var owlController_1 = __webpack_require__(/*! _util/owlController */ "./src/core/utils/owlController.ts");
var log_1 = __webpack_require__(/*! ./utils/log */ "./src/core/utils/log.ts");
var IM;
if (true) {
    IM = __webpack_require__(/*! _core/im */ "./src/core/im/index.ts").default;
}
var PUB;
if (true) {
    PUB = __webpack_require__(/*! _core/pub */ "./src/core/pub/index.ts").default;
}
var DATA;
if (true) {
    DATA = __webpack_require__(/*! _core/data */ "./src/core/data/index.ts").default;
}
var KEFU;
if (true) {
    KEFU = __webpack_require__(/*! _core/kefu */ "./src/core/kefu/index.ts").default;
}
var CORPORATION;
if (true) {
    CORPORATION = __webpack_require__(/*! _core/corporation */ "./src/core/corporation/index.ts").default;
}
var CALL;
if (true) {
    CALL = __webpack_require__(/*! _core/call */ "./src/core/call/index.ts").default;
}
var CHATROOM;
if (true) {
    CHATROOM = __webpack_require__(/*! _core/chatroom */ "./src/core/chatroom/index.ts").default;
}
// 用于判断 SDK 是否重复初始化,当前 SDK 只支持单例
var isInit = false;
var MTDX = /** @class */ (function () {
    function MTDX(opts) {
        var _this = this;
        this.on = eventEmitter_1.default.on.bind(eventEmitter_1.default);
        this.emit = eventEmitter_1.default.emit.bind(eventEmitter_1.default);
        this.once = eventEmitter_1.default.once.bind(eventEmitter_1.default);
        this.loginSDK = null;
        this.imSDK = null;
        this.pubSDK = null;
        this.dataSDK = null;
        this.kefuSDK = null;
        this.corporationSDK = null;
        this.callSDK = null;
        this.chatroomSDK = null;
        this.generalKefuSDK = null;
        this.HTTP = http_1.default;
        this.loginWay = 'ws';
        this.CONSTANT = {
            SESSION_TYPE: constant_1.SESSION_TYPE,
            MESSAGE: constant_1.MESSAGE_TYPE,
            LOGIN_STATUS: constant_1.LOGIN_STATUS,
            LOGIN_EVENT: constant_1.LOGIN_EVENT,
            MESSAGE_EVENT: constant_1.MESSAGE_EVENT,
            MESSAGE_STATUS: constant_1.MESSAGE_STATUS,
            SESSION_EVENT: constant_1.SESSION_EVENT,
            CANCEL_STATUS: constant_1.CANCEL_STATUS,
            MESSAGE_RESCODE: {
                RES_FORBIDDEN_GIM_CHAT: constant_1.RESCODE.RES_FORBIDDEN_GIM_CHAT
            }
        };
        this.base64 = base64_1.default;
        this.getSvrTime = getSvrTime_1.default;
        if (isInit) {
            log_1.default.error('MTDX::constructor Web SDK 已经初始化过,请勿重复初始化 SDK');
            return;
        }
        isInit = true;
        log_1.default.init(opts.logan, opts.closeConsoleLog);
        try {
            log_1.default.log('MTDX::constructor init sdk version:' + this.getSDKVersion() + ' params:' + JSON.stringify(opts));
        }
        catch (error) {
            log_1.default.log('MTDX::constructor init sdk exception:' + error);
        }
        if (opts) {
            if (opts.env !== constant.ENV.ONLINE && opts.env !== constant.ENV.ST && opts.env !== constant.ENV.TEST) {
                log_1.default.warn('传入env参数无效,现已重置为online');
                opts.env = constant.ENV.ONLINE;
            }
            opts.appId = opts.appId || opts.appid || 1;
            if (opts.appId <= 0) {
                log_1.default.error('传入appid参数错误 appid:' + opts.appId);
            }
            opts.av = opts.av || '';
            opts.deviceType = opts.deviceType || opts.dt || 2;
            opts.deviceId = opts.deviceId || uuid_1.default.next();
            if (typeChecker_1.default.isArray(opts.multiChannelIds) && opts.multiChannelIds.length > 0) {
                opts.channelId = opts.multiChannelIds[0];
            }
            if (opts.useHTTPS === void 0) {
                opts.useHTTPS = true;
            }
        }
        if (!typeChecker_1.default.isNumber(opts.localSessionNumber)) {
            opts.localSessionNumber = 1000;
        }
        deviceInfo_1.default.setDeviceType(opts.deviceType);
        userData_1.default.setAll(opts);
        // 微信场景下,自动关闭长轮询
        if (false) {}
        if (opts.useHTTPS) {
            if (false) {}
            else {
                log_1.default.log('Web SDK 已经开启 HTTPS');
            }
        }
        // 初始化大象数据组上报日志模块
        if (true) {
            analytics_1.default.init(opts.magic);
            owlController_1.default.init(opts.raptor);
        }
        this.HTTP.setEnv(opts.env);
        if (opts.defaultDomain) {
            this.HTTP.setDefaultDomain(opts.defaultDomain);
        }
        this.loginSDK = new login_1.default(opts);
        if (IM) {
            MTDX.IMSDK = IM;
            this.imSDK = new IM(this.loginSDK);
        }
        if (PUB) {
            MTDX.PubSDK = PUB;
            this.pubSDK = new PUB(this.loginSDK);
        }
        if (DATA) {
            MTDX.DataSDK = DATA;
            this.dataSDK = new DATA(this.loginSDK);
        }
        if (KEFU) {
            MTDX.KefuSDK = KEFU;
            this.kefuSDK = new KEFU(this.loginSDK);
        }
        if (CORPORATION) {
            MTDX.CorporationSDK = CORPORATION;
            this.corporationSDK = new CORPORATION(this.loginSDK);
        }
        if (CALL) {
            MTDX.CallSDK = CALL;
            this.callSDK = new CALL(this.loginSDK);
        }
        if (CHATROOM) {
            MTDX.ChatroomSDK = CHATROOM;
            this.chatroomSDK = new CHATROOM(this.loginSDK);
        }
        eventEmitter_1.default.on(constant_1.LOGIN_EVENT.USE_LONG_POLLING, function (longPolling) {
            _this.loginWay = longPolling;
        });
    }
    MTDX.fromBase64ToMessage = function (base64Str, version, workerUserData) {
        if (version === void 0) { version = 1; }
        if (workerUserData === void 0) { workerUserData = null; }
        if (false) {}
        return protocol_1.default.Response.fromBase64(base64Str, version);
    };
    MTDX.getUuid = function () {
        return uuid_1.default.next();
    };
    MTDX.prototype.getSDKVersion = function () {
        return "4.22.144";
    };
    MTDX.prototype.login = function (username, password, supportMultiDevices, pushToken) {
        this.loginSDK.login(username, password, supportMultiDevices, pushToken);
    };
    MTDX.prototype.loginWithUidAndToken = function (uid, token, supportMultiDevices, pushToken) {
        this.loginSDK.loginWithUidAndToken(uid, token, supportMultiDevices, pushToken);
    };
    MTDX.prototype.loginWithVisitor = function (uid, xsid) {
        this.loginSDK.loginWithVisitor(uid, xsid);
    };
    MTDX.prototype.getVisitorInfoAndLogin = function () {
        var _this = this;
        this.HTTP.getVisitorUidAndToken({
            success: function (_a) {
                var rescode = _a.rescode, data = _a.data;
                if (rescode === 0) {
                    // 这里不用data中的`uid`字段的原因是：uid为long型，可能存在溢出风险
                    _this.loginWithVisitor(data.uidStr, data.xsid);
                }
                else {
                    log_1.default.error("\u6E38\u5BA2\u767B\u5F55\u5931\u8D25:", data.uid, data.message);
                }
            }
        });
    };
    MTDX.prototype.logout = function () {
        log_1.default.log('MTDX::logout');
        this.loginSDK.logout();
    };
    MTDX.prototype.logoutByFalseKickoff = function (rescode) {
        this.loginSDK.logoutByFalseKickoff(rescode);
    };
    MTDX.prototype.getUid = function () {
        return this.loginSDK.getUID();
    };
    MTDX.prototype.fromBase64ToBuffer = function (base64Str, Msg) {
        return (new Msg()).parserFromBuffer(base64_1.default.b64toBA(base64Str).buffer);
    };
    MTDX.prototype.fromBase64ToMessage = function (base64Str, version) {
        if (version === void 0) { version = 1; }
        return protocol_1.default.Response.fromBase64(base64Str, version);
    };
    MTDX.prototype.getCts = function () {
        return timer_1.default.get();
    };
    MTDX.prototype.reconnect = function () {
        this.loginSDK.reconnect();
    };
    MTDX.prototype.setSwimlane = function (swimlane) {
        userData_1.default.set('swimlane', swimlane);
        log_1.default.log('MTDX::setSwimlane swimlane:' + userData_1.default.get('swimlane'));
    };
    MTDX.getLogModule = function () {
        return log_1.default;
    };
    MTDX.constant = constant;
    MTDX.IMSDK = IM;
    MTDX.PubSDK = PUB;
    MTDX.DataSDK = DATA;
    MTDX.KefuSDK = KEFU;
    MTDX.CorporationSDK = CORPORATION;
    MTDX.CallSDK = CALL;
    MTDX.ChatroomSDK = CHATROOM;
    MTDX.HTTP = http_1.default;
    MTDX.getSvrTime = getSvrTime_1.default;
    return MTDX;
}());
exports.default = MTDX;


//# sourceURL=webpack://MTDX/./src/core/index.ts?